import React from "react";
import ReactDOM from "react-dom";
import { Toast } from "antd-mobile";
import "react-virtualized/styles.css";
// 导入字体图标样式文件
import "./assets/fonts/iconfont.css";
// 导入axios
import axios from "axios";
// 导入antd-mobile样式
import "antd-mobile/dist/antd-mobile.css";
// 放在antd-mobile样式之后，防止被覆盖
import "./index.css";
// 导入BASE_URL
import {BASE_URL } from "./utils/url.js"
import App from "./App"; // 将App组件在最后导入，防止其中单页面的样式被后引入的样式文件覆盖
axios.defaults.baseURL = "http://localhost:8080/"; // 请求基础地址
axios.defaults.timeout = 15000; // 最大请求时长
// 网络请求过滤器
axios.interceptors.request.use((config) => {
  // config请求对象
  // 发起请求前展示进度条
  Toast.loading("加载中...", 0);
  return config;
},(error)=>{
  console.log(error)
  return Promise.reject(error);
  }
);
axios.interceptors.response.use((config) => {
  if ( config.data.description !== "请求成功" ) {
    Toast.fail("数据加载失败!");
  }else {
  Toast.hide();
}
  return config;
},
  (error) =>{
    Toast.fail("数据加载失败!");
    return Promise.reject(error);
  }
);
React.$http = axios; // 绑定全局axios请求
React.BASE_URL = BASE_URL;

/*
  使用第一种render模式报错，这是因为React.StrictMode组件开启了严格模式，
  需要使用第二种render模式
* Warning: A string ref, "slider", has been found within a strict mode tree. String refs are a source of potential bugs and should be avoided. We recommend using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref
* */
// ReactDOM.render(
//   <React.StrictMode>
//     <App />
//   </React.StrictMode>,
//   document.getElementById('root')
// );
ReactDOM.render(<App />, document.getElementById("root"));
